package com.gml.design.other.singleton;

/**
 * @ClassName : Singleton01
 * @Description : 单例模式第一种
 *          饿汉式
 *          类加载到内存后，就实例化一个单例，JVM保证线程安全
 *          简单实用
 *          唯一缺点，不管用到与否，类加载时就完成实例化
 * @Author : gml
 * @Date: 2021-04-01 13:52
 */
public class Singleton01 {
    //静态保证线程安全
    private static final Singleton01 INSTANCE = new Singleton01();

    private Singleton01(){
    }

    public static Singleton01 getInstance(){
        return INSTANCE;
    }

    public void say(){
        System.out.println("hello");
    }

    public static void main(String[] args) {
        Singleton01 singleton01 = Singleton01.getInstance();
        Singleton01 singleton02 = Singleton01.getInstance();

        System.out.println(singleton01 == singleton02);
    }

}
